#include "Base/CurrectThread.h"
#include <unistd.h>
#include <sys/syscall.h>
#include <errno.h>

namespace toym
{

thread_local char CurrectThread::threadName[16] = { 0 };
thread_local char CurrectThread::tidStr[11] = { 0 };
thread_local const char* CurrectThread::pTidStr = nullptr;
thread_local pid_t CurrectThread::tid = 0;
thread_local int CurrectThread::s_err = 0;

void CurrectThread::setThreadName(const char* name) {
    for (int i = 0; i < 16 && name[i] != '\0'; ++i)
        threadName[i] = name[i];
}

char* CurrectThread::getThreadName() {
    return threadName;
}

pid_t CurrectThread::getTid() {
    if (tid == 0) {
        tid = static_cast<pid_t>(::syscall(SYS_gettid));
    }
    return tid;
}

} // namespace toym
